const axios = require('axios');
const fs = require('fs')

// 获取小空间文件
axios.get('https://small-space.yuque.com/api/v2/repos/cabin/webgis_config/docs/gl7ivgal56vv6ain',{
    headers:{
        "X-Auth-Token": "hIFWrCBztoN8aaFizGkrA9yq5j38w6AKMgqEUqte",
    }
}).then((response) => {
    const {data} = response
    let markdown = data.data.body
    fs.writeFile('../../MarkDown/getMd1.md',markdown,(err)=>{
        if(err){
            console.log(err);
        }else{
            console.log('文件请求成功！');
        }
    })
}).catch((err) => {
    console.log('文件请求失败！',err);
})

// 获取小空间的目录
axios.get('https://small-space.yuque.com/api/v2/repos/cabin/webgis_config',{
    headers:{
        "X-Auth-Token": "hIFWrCBztoN8aaFizGkrA9yq5j38w6AKMgqEUqte",
    }
}).then((response) => {
    const {data} = response
    let markdown = data.data.toc
    fs.writeFile("../../MarkDown/list.md",markdown,(err) => {
        if(err){
            console.log(err);
        }else{
            console.log('目录请求成功！');
        }
    })
}).catch((err) => {
    console.log('目录请求失败！',err);
})

// 获取个人空间的文件
axios.get('https://www.yuque.com/api/v2/repos/kikigao/zaggkp/docs/rd81ll29cmc2vmeg',{
    headers:{
        "X-Auth-Token":"hIFWrCBztoN8aaFizGkrA9yq5j38w6AKMgqEUqte",
    }
}).then((response) => {
    const {data} = response
    markdown = data.data.body
    fs.writeFile('../../MarkDown/getMd2.md',markdown,(err) => {
        if(err){
            console.log(err);
        }else{
            console.log('文件请求成功！');
        }
    })
}).catch((err) => {
    console.log('文件请求失败！',err);
})

// 获取用户个人信息
axios.get('https://www.yuque.com/api/v2/user',{
    headers:{
        "X-Auth-Token":"hIFWrCBztoN8aaFizGkrA9yq5j38w6AKMgqEUqte"
    }
}).then((response) => {
    const {data} = response
    console.log('个人信息获取成功：',data.data);
}).catch((err) => {
    console.log('个人信息获取失败！',err);
})